
console.log( '- - - 1 - - -');
const first = new Promise((resolve,reject)=>{
    setTimeout(resolve, 0, '兑现(first)');
});
first.then( result => console.log( 'first then: ', result ) );

console.log( '- - - 2 - - -');
const second = new Promise((resolve,reject)=>{
    setTimeout(resolve, 1000, '兑现(second)');
});
second.then( result => console.log( 'second then: ', result ) );

console.log( '- - - 3 - - -');
const third = new Promise((resolve,reject)=>{
    setTimeout(resolve, 500, '兑现(third)');
});
third.then( result => console.log( 'third then: ', result ) );

console.log( '- - - 4 - - -');
const promises = [ first, second, third ];

const last = Promise.all( promises );
last.then( results => console.log( results ) )
    .catch( reason => console.log( reason ) );

// 总结
// Promise.all( iterable )
// 1、参数iterable表示一组Promise实例，可以是 Array、Set、Map
// 2、Promise.all 方法仅返回单个 Promise实例
// 3、当参数iterable中所有的Promise实例都被兑现时，Promise.all返回的Promise实例也被兑现
//    此时由Promise.all所返回的Promise实例中就会包含iterable中所有Promise实例兑现后的结果(以数组形式存储)
// 4、只要参数iterable中有一个Promise实例被拒绝，则Promise.all返回的Promise实例立即被拒绝
//    此时由Promise.all所返回的Promise实例就可以 reject 到第一个拒绝信息(或错误信息)